﻿/*

 @Name: layui WebIM 1.0.0
 @Author：贤心
 @Date: 2014-04-25
 @Blog: http://sentsin.com
 
 */

var config, dom = [$(window), $(document), $('html'), $('body')], xxim = {}, answer = Array(), timeout = true, timeids = Array(), timeid = 0;
xxim.Initialization = function (uid, username, userface, friend) {
    config = {
        msgurl: '私信地址',
        chatlogurl: '/wp_MessageRecord.htm?receiverId=',
        aniTime: 200,
        right: -232,
        api: {
            friend: friend, //好友列表接口
        },
        user: { //当前用户信息
            id: uid,
            name: username,
            face: userface
        },

        //自动回复内置文案，也可动态读取数据库配置
        autoReplay: [
            '您好，我现在有事不在，一会再和您联系。',
        ],

        chating: {},
        hosts: (function () {
            var dk = location.href.match(/\:\d+/);
            dk = dk ? dk[0] : '';
            return 'http://' + document.domain + dk + '/';
        })(),
        stopMP: function (e) {
            e ? e.stopPropagation() : e.cancelBubble = true;
        }
    }
}

//主界面tab
xxim.tabs = function (index) {
    var node = xxim.node;
    node.tabs.eq(index).addClass('xxim_tabnow').siblings().removeClass('xxim_tabnow');
    node.list.eq(index).show().siblings('.xxim_list').hide();
    if (node.list.eq(index).find('li').length === 0) {
        xxim.getDates(index);
    }
};

//节点
xxim.renode = function () {
    var node = xxim.node = {
        tabs: $('#xxim_tabs>span'),
        list: $('.xxim_list'),
        online: $('.xxim_online'),
        setonline: $('.xxim_setonline'),
        onlinetex: $('#xxim_onlinetex'),
        xximon: $('#xxim_on'),
        layimFooter: $('#xxim_bottom'),
        xximHide: $('#xxim_hide'),
        xximSearch: $('#xxim_searchkey'),
        searchMian: $('#xxim_searchmain'),
        closeSearch: $('#xxim_closesearch'),
        layimMin: $('#layim_min')
    };
};

//主界面缩放
xxim.expend = function () {
    var node = xxim.node;
    if (xxim.layimNode.attr('state') !== '1') {
        xxim.layimNode.stop().animate({ right: config.right }, config.aniTime, function () {
            node.xximon.addClass('xxim_off');
            try {
                localStorage.layimState = 1;
            } catch (e) { }
            xxim.layimNode.attr({ state: 1 });
            node.layimFooter.addClass('xxim_expend').stop().animate({ marginLeft: config.right }, config.aniTime / 2);
            node.xximHide.addClass('xxim_show');
        });
    } else {
        xxim.layimNode.stop().animate({ right: 1 }, config.aniTime, function () {
            node.xximon.removeClass('xxim_off');
            try {
                localStorage.layimState = 2;
            } catch (e) { }
            xxim.layimNode.removeAttr('state');
            node.layimFooter.removeClass('xxim_expend');
            node.xximHide.removeClass('xxim_show');
        });
        node.layimFooter.stop().animate({ marginLeft: 0 }, config.aniTime);
    }
};

//初始化窗口格局
xxim.layinit = function () {
    var node = xxim.node;

    //主界面
    try {
        if (!localStorage.layimState) {
            config.aniTime = 0;
            localStorage.layimState = 1;
        }
        if (localStorage.layimState === '1') {
            xxim.layimNode.attr({ state: 1 }).css({ right: config.right });
            node.xximon.addClass('xxim_off');
            node.layimFooter.addClass('xxim_expend').css({ marginLeft: config.right });
            node.xximHide.addClass('xxim_show');
        }
    } catch (e) {
        layer.msg(e.message, 3, -1);
    }
};

//聊天窗口
xxim.popchat = function (param) {
    var node = xxim.node, log = {};

    log.success = function (layero) {


        layer.setMove();

        xxim.chatbox = layero.find('#layim_chatbox');
        log.chatlist = xxim.chatbox.find('.layim_chatmore>ul');

        log.chatlist.html('<li data-id="' + param.id + '" type="' + param.type + '"  id="layim_user' + param.type + param.id + '"><span>' + param.name + '</span><em>×</em></li>')
        xxim.tabchat(param, xxim.chatbox);

        //最小化聊天窗
        xxim.chatbox.find('.layer_setmin').on('click', function () {
            var indexs = layero.attr('times');
            layero.hide();
            $("#layim_min").attr("style", "left:calc();");
            node.layimMin.text(xxim.nowchat.name).show();
            //$("#layim_min").attr("style", "left:calc();");
        });

        //关闭窗口
        xxim.chatbox.find('.layim_close').on('click', function () {
            var indexs = layero.attr('times');
            layero.hide();
            //$("#layim_min").attr("style", "left:calc();");
            //node.layimMin.text(xxim.nowchat.name).show();
            layer.close(indexs);
            xxim.chatbox = null;
            config.chating = {};
            config.chatings = 0;
            //停止获取所有消息
            $(timeids).each(function (i, e) {
                window.clearInterval(e.id);
            });
            timeids=Array();
        });

        //关闭某个聊天
        //log.chatlist.on('mouseenter', 'li', function () {
        //    $(this).find('em').show();
        //}).on('mouseleave', 'li', function () {
        //    $(this).find('em').hide();
        //});

        log.chatlist.on('click', 'li em', function (e) {
            var parents = $(this).parent(), dataType = parents.attr('type');
            var dataId = parents.attr('data-id'), index = parents.index();
            var chatlist = log.chatlist.find('li'), indexs;

            config.stopMP(e);

            delete config.chating[dataType + dataId];
            config.chatings--;

            parents.remove();
            $('#layim_area' + dataType + dataId).remove();
            if (dataType === 'group') {
                $('#layim_group' + dataType + dataId).remove();
            }

            if (parents.hasClass('layim_chatnow')) {
                if (index === config.chatings) {
                    indexs = index - 1;
                } else {
                    indexs = index + 1;
                }
                xxim.tabchat(config.chating[chatlist.eq(indexs).attr('type') + chatlist.eq(indexs).attr('data-id')]);
            }

            if (log.chatlist.find('li').length === 1) {
                log.chatlist.parent().hide();
            }
        });

        //聊天选项卡
        log.chatlist.on('click', 'li', function () {
            var othis = $(this), dataType = othis.attr('type'), dataId = othis.attr('data-id');
            xxim.tabchat(config.chating[dataType + dataId]);
        });

        //发送热键切换
        log.sendType = $('#layim_sendtype'), log.sendTypes = log.sendType.find('span');
        $('#layim_enter').on('click', function (e) {
            config.stopMP(e);
            log.sendType.show();
        });
        log.sendTypes.on('click', function () {
            log.sendTypes.find('i').text('')
            $(this).find('i').text('√');
        });

        xxim.transmit();
    };

    log.html = '<div class="layim_chatbox" id="layim_chatbox">'
            + '<h6>'
            + '<span class="layim_move"></span>'
            + '    <span class="layim_face" ><img src="' + param.face + '" ></span>'
            + '    <span class="layim_names" >' + param.name + '</span>'
            + '    <span class="layim_rightbtn">'
            + '        <i class="layer_setmin"></i>'
            + '        <i class="layim_close"></i>'
            + '    </span>'
            + '</h6>'
            + '<div class="layim_chatmore" id="layim_chatmore">'
            + '    <ul class="layim_chatlist"></ul>'
            + '</div>'
            + '<div class="layim_groups" id="layim_groups"></div>'
            + '<div class="layim_chat">'
            + '    <div class="layim_chatarea" id="layim_chatarea">'
            + '        <ul class="layim_chatview layim_chatthis"  id="layim_area' + param.type + param.id + '">'
            + '</ul></div>'
            + '    <div class="layim_tool">'
            //+ '        <i class="layim_addface" title="发送表情"></i>'
            //+ '        <a href="javascript:;"><i class="layim_addimage" title="上传图片"></i></a>'
            //+ '        <a href="javascript:;"><i class="layim_addfile" title="上传附件"></i></a>'
            + '        <a href="" target="_blank" class="layim_seechatlog"><i></i>聊天记录</a>'
            + '    </div>'
            + '    <textarea class="layim_write" id="layim_write"></textarea>'
            + '    <div class="layim_send">'
            + '        <div class="layim_sendbtn" id="layim_sendbtn">发送</div>'
            //+ '        <div class="layim_sendtype" id="layim_sendtype">'
            //+ '            <span><i>√</i>按Enter键发送</span>'
            //+ '            <span><i></i>按Ctrl+Enter键发送</span>'
            //+ '        </div>'
            + '    </div>'
            + '</div>'
            + '</div>';

    if (config.chatings < 1) {
        $.layer({
            type: 1,
            border: [0],
            title: false,
            shade: [0],
            area: ['620px', '493px'],
            move: ['.layim_chatbox .layim_move', true],
            moveType: 1,
            closeBtn: false,
            offset: [(($(window).height() - 493) / 2) + 'px', ''],
            page: {
                html: log.html
            }, success: function (layero) {
                log.success(layero);
            }
        })
    } else {
        log.chatmore = xxim.chatbox.find('#layim_chatmore');
        log.chatarea = xxim.chatbox.find('#layim_chatarea');

        log.chatmore.show();

        log.chatmore.find('ul>li').removeClass('layim_chatnow');
        log.chatmore.find('ul').append('<li data-id="' + param.id + '" type="' + param.type + '" id="layim_user' + param.type + param.id + '" class="layim_chatnow"><span>' + param.name + '</span><em>×</em></li>');

        log.chatarea.find('.layim_chatview').removeClass('layim_chatthis');
        log.chatarea.append('<ul class="layim_chatview layim_chatthis" id="layim_area' + param.type + param.id + '"></ul>');

        xxim.tabchat(param);
    }

    //群组
    log.chatgroup = xxim.chatbox.find('#layim_groups');
    if (param.type === 'group') {
        log.chatgroup.find('ul').removeClass('layim_groupthis');
        log.chatgroup.append('<ul class="layim_groupthis" id="layim_group' + param.type + param.id + '"></ul>');
        xxim.getGroups(param);
    }
    //点击群员切换聊天窗
    log.chatgroup.on('click', 'ul>li', function () {
        xxim.popchatbox($(this));
    });
};

//定位到某个聊天队列
xxim.tabchat = function (param) {
    var node = xxim.node, log = {}, keys = param.type + param.id;
    xxim.nowchat = param;

    xxim.chatbox.find('#layim_user' + keys).addClass('layim_chatnow').siblings().removeClass('layim_chatnow');
    xxim.chatbox.find('#layim_area' + keys).addClass('layim_chatthis').siblings().removeClass('layim_chatthis');
    xxim.chatbox.find('#layim_group' + keys).addClass('layim_groupthis').siblings().removeClass('layim_groupthis');

    xxim.chatbox.find('.layim_face>img').attr('src', param.face);
    xxim.chatbox.find('.layim_face, .layim_names').attr('href', param.href);
    xxim.chatbox.find('.layim_names').text(param.name);

    xxim.chatbox.find('.layim_seechatlog').attr('href', config.chatlogurl + "" + config.user.id + "&senderid=" + param.id);

    log.groups = xxim.chatbox.find('.layim_groups');
    if (param.type === 'group') {
        log.groups.show();
    } else {
        log.groups.hide();
    }

    $('#layim_write').focus();


    //初次定位时 读取一次聊天信息
    getMessage(param.id, "em");

    //定时读取 聊天记录
    var timeout = true;
    $(timeids).each(function (i, e) {
        if (e.key == param.id) {
            timeout = false;
            return false;
        }
    });
    if (timeout) {
        //重新定位 到当前聊天信息读取
        var timeid = window.setInterval(function () {
            getMessage(param.id, "em");
        }, 3000);
        timeout = true;
        timeids.push({ key: param.id, id: timeid });
    }

    $(timeids).each(function (i, e) {
        if (e.key != param.id) {
            window.clearInterval(e.id);
            timeids.splice(e, 1);
        }
    });
};

//弹出聊天窗
xxim.popchatbox = function (othis) {
    var node = xxim.node, dataId = othis.attr('data-id'), param = {
        id: dataId, //用户ID
        type: othis.attr('type'),
        name: othis.find('.xxim_onename').text(),  //用户名
        face: othis.find('.xxim_oneface').attr('src'),  //用户头像
        href: config.hosts + 'user/' + dataId //用户主页
    }, key = param.type + dataId;
    xxim.param = param;
    if (!config.chating[key]) {
        //第一次加载窗体 获取聊天信息
        //xxim.getMssage(dataId, "im", "em");
        xxim.popchat(param);
        config.chatings++;
    } else {
        xxim.tabchat(param);
    }
    config.chating[key] = param;

    var chatbox = $('#layim_chatbox');
    if (chatbox[0]) {
        node.layimMin.hide();
        chatbox.parents('.xubox_layer').show();
    }
};

//请求群员
xxim.getGroups = function (param) {
    var keys = param.type + param.id, str = '',
    groupss = xxim.chatbox.find('#layim_group' + keys);
    groupss.addClass('loading');
    config.json(config.api.groups, {}, function (datas) {
        if (datas.status === 1) {
            var ii = 0, lens = datas.data.length;
            if (lens > 0) {
                for (; ii < lens; ii++) {
                    str += '<li data-id="' + datas.data[ii].id + '" type="one"><img src="' + datas.data[ii].face + '"><span class="xxim_onename">' + datas.data[ii].name + '</span></li>';
                }
            } else {
                str = '<li class="layim_errors">没有群员</li>';
            }

        } else {
            str = '<li class="layim_errors">' + datas.msg + '</li>';
        }
        groupss.removeClass('loading');
        groupss.html(str);
    }, function () {
        groupss.removeClass('loading');
        groupss.html('<li class="layim_errors">请求异常</li>');
    });
};
//聊天模版
xxim.msgTemple = function (param, type) {
    return '<li class="' + (type === 'me' ? 'layim_chateme' : '') + '">'
        + '<div class="layim_chatuser">'
            + function () {
                if (type === 'me') {
                    return '<span class="layim_chattime">' + param.time + '</span>'
                           + '<span class="layim_chatname">' + param.name + '</span>'
                           + '<img src="' + param.face + '" >';
                } else {
                    return '<img src="' + param.face + '" >'
                           + '<span class="layim_chatname">' + param.name + '</span>'
                           + '<span class="layim_chattime">' + param.time + '</span>';
                }
            }()
        + '</div>'
        + '<div class="layim_chatsay">' + param.content + '<em class="layim_zero"></em></div>'
    + '</li>';
};

//消息传输
xxim.transmit = function () {
    var node = xxim.node, log = {};
    node.sendbtn = $('#layim_sendbtn');
    node.imwrite = $('#layim_write');

    //发送
    log.send = function () {
        var data = {
            content: node.imwrite.val(),
            id: xxim.nowchat.id,
            sign_key: '', //密匙
            _: +new Date
        };

        if (data.content.replace(/\s/g, '') === '') {
            layer.tips('说点啥呗！', '#layim_write', 2);
            node.imwrite.focus();
        } else {
            //此处皆为模拟
            var keys = xxim.nowchat.type + xxim.nowchat.id;
            log.imarea = xxim.chatbox.find('#layim_area' + keys);

            //消息发送
            var opart = new jsonRow();
            senderMessage(config.user.name, xxim.nowchat.id, xxim.nowchat.name, data.content);

            //opart.AddCell("receiverId", xxim.nowchat.id);
            //opart.AddCell("receiverNick", xxim.nowchat.name);
            //opart.AddCell("senderNick", config.user.name);
            //opart.AddCell("message", data.content);
            //opart.AddCell("ACTION", "Sender");
            //ajaxComm(opart);

            //消息接受
            setTimeout(function () {
                getMessage(xxim.nowchat.id, "em");
                //xxim.getMssage(xxim.nowchat.id, "em", "em");
            }, 3000);
        }

    };

    node.sendbtn.on('click', log.send);

    node.imwrite.keyup(function (e) {
        if (e.keyCode === 13) {
            log.send();
        }
    });
};
//消息发送
xxim.sendMessage = function () {
    var node = xxim.node, log = {};
    node.sendbtn = $('#layim_sendbtn');
    node.imwrite = $('#layim_write');
    var keys = xxim.nowchat.type + xxim.nowchat.id;
    log.imarea = xxim.chatbox.find('#layim_area' + keys);

    log.imarea.append(xxim.msgTemple({
        time: xxim.dataTime("-"),
        name: config.user.name,
        face: config.user.face,
        content: node.imwrite.val()
    }, 'me'));
    node.imwrite.val('').focus();
    log.imarea.scrollTop(log.imarea[0].scrollHeight);
};

//消息获取
xxim.getMessage = function (data) {
    var node = xxim.node, log = {};
    node.sendbtn = $('#layim_sendbtn');
    node.imwrite = $('#layim_write');
    var keys = xxim.nowchat.type + xxim.nowchat.id;
    log.imarea = xxim.chatbox.find('#layim_area' + keys);

    //消息接受
    if (data.total > 0) {
        $(data.rows).each(function (i, e) {
            log.imarea.append(xxim.msgTemple({
                time: e.MESSAGE_SEND_TIME,
                name: e.MESSAGE_SENDER_NICK,
                face: e.SENDER_PIC,
                content: e.CONTENT_FOR_MESSAGE
            }));
        });
    }
    log.imarea.scrollTop(log.imarea[0].scrollHeight);
}

//获取时间
xxim.dataTime = function CurentTime(partten) {
    var now = new Date();
    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日
    var hh = now.getHours();            //时
    var mm = now.getMinutes();          //分
    var clock = year + partten;

    if (month < 10) { clock += "0" };
    clock += month + partten;

    if (day < 10) { clock += "0" };
    clock += day + " ";

    if (hh < 10) { clock += "0" };
    clock += hh + ":";

    if (mm < 10) { clock += '0' };
    clock += mm;
    return clock;
}

//事件
xxim.event = function () {
    var node = xxim.node;

    //主界面tab
    node.tabs.eq(0).addClass('xxim_tabnow');
    node.tabs.on('click', function () {
        var othis = $(this), index = othis.index();
        xxim.tabs(index);
    });

    //列表展收
    node.list.on('click', 'h5', function () {
        var othis = $(this), chat = othis.siblings('.xxim_chatlist'), parentss = othis.parent();
        if (parentss.hasClass('xxim_liston')) {
            chat.hide();
            parentss.removeClass('xxim_liston');
        } else {
            chat.show();
            parentss.addClass('xxim_liston');
        }
    });

    //设置在线隐身
    node.online.on('click', function (e) {
        config.stopMP(e);
        node.setonline.show();
    });
    //node.setonline.find('span').on('click', function (e) {
    //    var index = $(this).index();
    //    config.stopMP(e);
    //    if (index === 0) {
    //        node.onlinetex.html('在线');
    //        node.online.removeClass('xxim_offline');
    //    } else if (index === 1) {
    //        node.onlinetex.html('隐身');
    //        node.online.addClass('xxim_offline');
    //    }
    //    node.setonline.hide();
    //});

    node.xximon.on('click', xxim.expend);
    node.xximHide.on('click', xxim.expend);

    //搜索
    node.xximSearch.keyup(function () {
        var val = $(this).val().replace(/\s/g, '');
        if (val !== '') {
            node.searchMian.show();
            node.closeSearch.show();
            //此处的搜索ajax参考xxim.getDates
            node.list.eq(3).html('<li class="xxim_errormsg">没有符合条件的结果</li>');
        } else {
            node.searchMian.hide();
            node.closeSearch.hide();
        }
    });
    node.closeSearch.on('click', function () {
        $(this).hide();
        node.searchMian.hide();
        node.xximSearch.val('').focus();
    });

    //弹出聊天窗
    config.chatings = 0;
    node.list.on('click', '.xxim_childnode', function () {
        var othis = $(this);
        xxim.popchatbox(othis);
    });

    //点击最小化栏
    node.layimMin.on('click', function () {
        $(this).hide();
        $('#layim_chatbox').parents('.xubox_layer').show();

    });


    //document事件
    dom[1].on('click', function () {
        node.setonline.hide();
        $('#layim_sendtype').hide();
    });
};

//请求列表数据
xxim.getDates = function (index) {
    var node = xxim.node, myf = node.list.eq(index);
    myf.addClass('loading');

    if (config.api.friend.records <= 0) {
        myf.html('<li class="xxim_errormsg">没有记录</li>');
        myf.removeClass('loading');
    }
    else {
        var i = 0, myflen = config.api.friend.rows.length, str = '';

        str += '<li data-id="1001" class="xxim_parentnode xxim_liston">'
               + '<h5><i></i><span class="xxim_parentname">最近聊天</span><em class="xxim_nums">（' + myflen + '）</em></h5>'
               + '<ul class="xxim_chatlist" style="display: block;">';
        $(config.api.friend.rows).each(function (i, e) {
            str += '<li data-id="' + e.id + '" class="xxim_childnode" type="' + (index === 0 ? 'one' : 'group') + '">';
            str += '<img src="' + e.face + '" class="xxim_oneface"><span class="xxim_onename">' + e.name + '</span>';
            str += '<p style="float:right">消息(<em style="color: red">' + e.msgCount + '</em>)</p></li>';
            answer.push(e);
        });
        str += '</ul></li>';

        myf.html(str);
        myf.removeClass('loading');
    }
};

//渲染骨架
xxim.view = function () {
    var xximNode = xxim.layimNode = $('<div id="xximmm" class="xxim_main">'
            + '<div class="xxim_top" id="xxim_top">'
            //+ '  <div class="xxim_search"><i></i><input id="xxim_searchkey" /><span id="xxim_closesearch">×</span></div>'
            + '  <div class="xxim_tabs" id="xxim_tabs"><span class="xxim_tabfriend" title="好友"><i></i></div>'
            + '  <ul class="xxim_list" style="display:block"></ul>'
            + '  <ul class="xxim_list"></ul>'
            + '  <ul class="xxim_list"></ul>'
            + '  <ul class="xxim_list xxim_searchmain" id="xxim_searchmain"></ul>'
            + '</div>'
            + '<ul class="xxim_bottom" id="xxim_bottom">'
            + '<li class="xxim_online" id="xxim_online">'
                + '<i class="xxim_nowstate"></i><span id="xxim_onlinetex">在线</span>'
                //+ '<div class="xxim_setonline">'
                //    + '<span><i></i>在线</span>'
                //    + '<span class="xxim_setoffline"><i></i>隐身</span>'
                //+ '</div>'
            + '</li>'
            //+ '<li class="xxim_mymsg" id="xxim_mymsg" title="我的私信"><i></i><a href="' + config.msgurl + '" target="_blank"></a></li>'
            //+ '<li class="xxim_seter" id="xxim_seter" title="设置">'
                //+ '<i></i>'
                //+ '<div class="">'
                //+ '</div>'
            //+ '</li>'
            + '<li title="我的消息" id="xxim_mymsg" class="xxim_mymsg"><p>消息(<em id="xxim_mymsgshu" style="color:red;">0</em>)</p></li>'
            + '<li class="xxim_hide" id="xxim_hide"><i></i></li>'
            + '<li id="xxim_on" class="xxim_icon xxim_on"></li>'
            + '<div class="layim_min" id="layim_min" style="left:calc()"></div>'
        + '</ul>'
    + '</div>');
    dom[3].append(xximNode);
};

//消息获取 加载
xxim.getMssage = function (mstype, status) {
    var opart = new jsonRow();
    opart.AddCell("mstype", mstype);
    opart.AddCell("status", status);
    opart.AddCell("ACTION", "GetMs");
    ajaxComm(opart);
}


//好友 数据加载
xxim.messageInitia = function (dt) {
    if (dt.records <= 0) {
        //修改 消息数量
        var ulli = xxim.node.list.eq(0).find("ul li").children().last().html("消息(<em style='color: red'>0</em>)");
        $("#xxim_mymsgshu").html("0");
        return true;
    }
    var str = "", tempAnswer = Array(), isTrue = false, temp1 = false;

    //发现如果是本人 则不能聊天
    if (dt.rows.length <= 1) {
        if (dt.rows[0].id == config.user.id) {
            layer.msg('自己不能和自己聊天哦！', 3, { shift: 6 });
            return false;
        }
    }
    //整理到全局
    $(dt.rows).each(function (i, e) {
        $(answer).each(function (j, k) {
            if (e.id == k.id) {
                isTrue = true;
                k.msgCount = e.msgCount;
            }
        });
        if (!isTrue) {
            tempAnswer.push(e);
            answer.push(e);
            isTrue = false;
        }
    });


    //加载 到临时列表
    var tempcount = 0;
    var myf = xxim.node.list.eq(0).find("ul");
    if (myf.length > 0) {
        for (var j = 0; j < answer.length; j++) {
            str += '<li data-id="' + answer[j].id + '" class="xxim_childnode" type="one">';
            str += '<img src="' + answer[j].face + '" class="xxim_oneface"><span class="xxim_onename">' + answer[j].name + '</span>';
            str += '<p style="float:right">消息(<em style="color: red">' + answer[j].msgCount + '</em>)</p></li>';
            tempcount += parseInt(answer[j].msgCount);
        }
        myf.html(str);
    }
    else {
        str += '<li data-id="1001" class="xxim_parentnode">'
                   + '<h5><i></i><span class="xxim_parentname">最近聊天</span><em class="xxim_nums">（' + answer.length + '）</em></h5>'
                   + '<ul class="xxim_chatlist">';
        for (var j = 0; j < answer.length; j++) {
            str += '<li data-id="' + answer[j].id + '" class="xxim_childnode" type="one">';
            str += '<img src="' + answer[j].face + '" class="xxim_oneface"><span class="xxim_onename">' + answer[j].name + '</span>';
            str += '<p style="float:right">消息(<em style="color: red">' + answer[j].msgCount + '</em>)</p></li>';
            tempcount += parseInt(answer[j].msgCount);
        }
        str += '</ul></li>';
        xxim.node.list.eq(0).html(str);
    }
    $("#xxim_mymsgshu").html(tempcount);
    return true;
}


